package com.xingji.caixia.adapter;

import android.support.v4.util.CircularArray;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

/**
 * Created by zyh on 2017/9/28.
 */

public class PageAdapter extends PagerAdapter {
    private int mChildCount = 0;

    CircularArray<ImageView> list = new CircularArray<>();

    public PageAdapter(CircularArray<ImageView> list) {
        this.list = list;
    }

    public PageAdapter() {
    }

    public void notify(CircularArray<ImageView> list){
        this.list = list;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView img = list.get(position % list.size());
        img.setTag(position);
        container.addView(img);
        return list.get(position % list.size());
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
